package com.atls.eduservice.service.impl;

import com.atls.eduservice.entity.EduComment;
import com.atls.eduservice.entity.EduTeacher;
import com.atls.eduservice.mapper.EduCommentMapper;
import com.atls.eduservice.service.EduCommentService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 评论 服务实现类
 * </p>
 *
 * @author testjava
 * @since 2021-04-05
 */
@Service
public class EduCommentServiceImpl extends ServiceImpl<EduCommentMapper, EduComment> implements EduCommentService {

    @Override
    public Map<String, Object> getCommentList(Page<EduComment> commentPage) {

        QueryWrapper<EduComment> wrapper=new QueryWrapper<>();
        wrapper.orderByDesc("id");
        baseMapper.selectPage(commentPage,wrapper);

        Map<String,Object> map=new HashMap<>();
        List<EduComment> records = commentPage.getRecords();
        long current =commentPage.getCurrent();
        long pages = commentPage.getPages();
        long size = commentPage.getSize();
        long total = commentPage.getTotal();
        boolean previous = commentPage.hasPrevious(); //上一页
        boolean next = commentPage.hasNext();

        map.put("records",records);
        map.put("current",current);
        map.put("pages",pages);
        map.put("size",size);
        map.put("total",total);
        map.put("previous",previous);
        map.put("next",next);
        return map;
    }
}
